package com.kolya.lockphone;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.util.Log;
import android.view.Menu;

public class SmsManagerActivity extends Activity
{

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sms_manager);

		try
		{
			ContentResolver CR = getContentResolver();
			// Query SMS
			Uri uriSms = Uri.parse("content://sms");
			String phoneString="15555215556";
			
			Cursor c = CR.query(uriSms, new String[]
			{ "_id", "thread_id", "address" }, "address="+phoneString, null, null);
			
			/*
			 * Cursor c = CR.query(uriSms, new String[] { "_id",
			 * "thread_id","address" }, null, null, null);
			 */

			/*
			 * Cursor android.content. ContentResolver.query(Uri uri, String[]
			 * projection, String selection, String[] selectionArgs, String
			 * sortOrder)
			 */
			System.out.println("sms count:" + c.getCount());

			if (null != c && c.moveToFirst())
			{
				do
				{
					System.out.println("phone:"+ c.getString(2));
					// Delete SMS
					long threadId = c.getLong(1);
					// CR.delete(Uri.parse("content://sms/" + threadId), null,
					// null);
					Log.d("deleteSMS", "threadId:: " + threadId);
				} while (c.moveToNext());
			}
		} catch (Exception e)
		{
			// TODO: handle exception
			Log.d("deleteSMS", "Exception:: " + e);
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_sms_manager, menu);
		return true;
	}

}
